package cn.org.xuanzp.nty.server.channel;

import cn.org.xuanzp.nty.server.handler.CommandHandler;
import cn.org.xuanzp.nty.server.adapter.NettyServerHandler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;

/**
 * @Classname NettyFtpServerChannelInitializer
 * @Description 初始化pipline主要添加对象传输功能
 * @Version 1.0.0
 * @Date 2024/9/22 16:39
 * @Created by xuanzp
 */
public class NettyServerChannelInitializer extends ChannelInitializer<Channel> {

    private CommandHandler commandHandler;

    public NettyServerChannelInitializer(CommandHandler commandHandler) {
        this.commandHandler = commandHandler;
    }

    @Override
    protected void initChannel(Channel ch) throws Exception {
        ch.pipeline()
                .addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)))
                .addLast(new NettyServerHandler(commandHandler))
                .addLast(new ObjectEncoder());
    }

}
